public class Leetcode55 {

    public static void main(String[] args) {
        System.out.println(canJump(new int[]{2, 3, 1, 1, 4}));
    }

    public static boolean canJump(int[] nums) {
        if (nums.length == 1) {
            return true;
        }

        int n = nums.length;
        for (int i = n - 2; i >= 0; i--) {
            if (nums[i] + i >= n - 1) {
                n = i + 1;
            }
        }

        return n == 1;
    }

}
